CC = g++
CFLAGS = -Wall -pedantic -I.

DEBUG_FLAGS = -O0 -g \
              -DIS_DEBUG \
              -DIS_DEBUG_NODES \
              -DIS_DEBUG_ENUM \
              -DIS_DEBUG_ITERS \
              -DIS_DEBUG_TRACE_ENUM
SUPERDEBUG_FLAGS = -O0 -g \
                   -DIS_DEBUG \
                   -DIS_DEBUG_NODES \
                   -DIS_DEBUG_ENUM \
                   -DIS_DEBUG_ITERS \
                   -DIS_DEBUG_TRACE_ENUM \
                   -DIS_DEBUG_ITERS \
                   -DIS_DEBUG_BBSPILL_COST \
                   -DIS_DEBUG_BOUNDS \
                   -DIS_DEBUG_DAG \
                   -DIS_DEBUG_DEPTH \
                   -DIS_DEBUG_FIX \
                   -DIS_DEBUG_FLOW \
                   -DIS_DEBUG_HIST \
                   -DIS_DEBUG_INFSBLTY_TESTS \
                   -DIS_DEBUG_ISSUE_TYPES \
                   -DIS_DEBUG_LATENCIES \
                   -DIS_DEBUG_MODEL \
                   -DIS_DEBUG_NODEDOM \
                   -DIS_DEBUG_READY_LIST \
                   -DIS_DEBUG_READY_LIST2 \
                   -DIS_DEBUG_RJ \
                   -DIS_DEBUG_SCHED \
                   -DIS_DEBUG_SCHED2 \
                   -DIS_DEBUG_SPD \
                   -DIS_DEBUG_PRINT_BOUNDS \
                   -DIS_DEBUG_PRINT_SCHEDS \
                   -DIS_DEBUG_SOLN_DETAILS_1 \
                   -DIS_DEBUG_SOLN_DETAILS_2 \
                   -DIS_DEBUG_OUTPUT_EDGES
RELEASE_FLAGS = -O3

_OBJS = generic/buffers \
        generic/logger \
        generic/graph \
        generic/random \
        generic/stats \
        generic/config \
        basic/machine_model \
        basic/sched_basic_data \
        basic/register \
        basic/data_dep \
        basic/ready_list \
        basic/gen_sched \
        list_sched/list_sched \
        relaxed/relaxed_sched \
        sched_region/sched_region \
        enum/hist_table \
        enum/enumerator \
        spill/bb_spill \
        main/main
QUICK_OBJS = $(_OBJS:%=obj/%.q.o)
DEBUG_OBJS = $(_OBJS:%=obj/%.d.o)
SUPERDEBUG_OBJS = $(_OBJS:%=obj/%.sd.o)
RELEASE_OBJS = $(_OBJS:%=obj/%.r.o)

all: $(QUICK_OBJS)
	@ echo "Building main binary: quick."
	@ $(CC) -o sched $(QUICK_OBJS) $(CFLAGS)

debug: $(DEBUG_OBJS)
	@ echo "Building main binary: debug."
	@ $(CC) -o dsched $(DEBUG_OBJS) $(CFLAGS) $(DEBUG_FLAGS)

superdebug: $(SUPERDEBUG_OBJS)
	@ echo "Building main binary: superdebug."
	@ $(CC) -o sdsched $(SUPERDEBUG_OBJS) $(CFLAGS) $(SUPERDEBUG_FLAGS)

release: $(RELEASE_OBJS)
	@ echo "Building main binary: release."
	@ $(CC) -o rsched $(RELEASE_OBJS) $(CFLAGS) $(RELEASE_FLAGS)

obj/%.q.o: %.cpp
	@ echo "Building" $(notdir $@)
	@ mkdir -p $(dir $@)
	@ $(CC) -c -o $@ $< $(CFLAGS)

obj/%.d.o: %.cpp
	@ echo "Building" $(notdir $@)
	@ mkdir -p $(dir $@)
	@ $(CC) -c -o $@ $< $(CFLAGS) $(DEBUG_FLAGS)

obj/%.sd.o: %.cpp
	@ echo "Building" $(notdir $@)
	@ mkdir -p $(dir $@)
	@ $(CC) -c -o $@ $< $(CFLAGS) $(SUPERDEBUG_FLAGS)

obj/%.r.o: %.cpp
	@ echo "Building" $(notdir $@)
	@ mkdir -p $(dir $@)
	@ $(CC) -c -o $@ $< $(CFLAGS) $(RELEASE_FLAGS)

clean:
	@ echo "Cleaning."
	@ rm -rf obj sched dsched sdsched rsched
